home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 114_01.zip / ED5.BDS < prev    next >
Text File  |  1993-06-01  |  3KB  |  194 lines

  1. /* Screen editor:  output format module
  2.  *
  3.  * Source: ed5.cc
  4.  * Version: May 15, 1981.
  5.  */
  6.  
  7. /* define globals */
  8.  
  9. #include ed.h
  10. #include bdscio.h
  11. #include ed1.ccc
  12. #include edext.cc
  13.  
  14. /* variables global to this module -----
  15.  
  16. int fmttab;        maximal tab length
  17. int fmtdev;        device flag -- YES/NO = LIST/CONSOLE
  18. int fmtwidth;        devide width.  LISTW/SCRNW1
  19.  
  20. fmtcol[i] is the first column at which buf[i] is printed.
  21. fmtsub() and fmtlen() assume fmtcol[] is valid on entry.
  22.  
  23. int fmtcol[MAXLEN1];
  24.  
  25. ----- */
  26.  
  27. /* direct output from this module to either the console or
  28.  * the list device.
  29.  */
  30.  
  31. fmtassn(listflag) int listflag;
  32. {
  33.     if (listflag==YES) {
  34.         fmtdev=YES;
  35.         fmtwidth=LISTW;
  36.     }
  37.     else {
  38.         fmtdev=NO;
  39.         fmtwidth=SCRNW1;
  40.     }
  41. }
  42.  
  43. /* adjust fmtcol[] to prepare for calls on
  44.  * fmtout() and fmtlen()
  45.  *
  46.  * NOTE:  this routine is needed as an efficiency
  47.  *        measure.  Without fmtadj(), calls on
  48.  *        fmtlen() become too slow.
  49.  */
  50.  
  51. fmtadj(buf,minind,maxind) char *buf; int minind,maxind;
  52. {
  53. int k;
  54.     /* line always starts at left margin */
  55.     fmtcol[0]=0;
  56.     /* start scanning at minind */
  57.     k=minind;
  58.     while (k<maxind) {
  59.         if (buf[k]==CR) {
  60.             break;
  61.         }
  62.         fmtcol[k+1]=fmtcol[k]+fmtlench(buf[k],fmtcol[k]);
  63.         k++;
  64.     }
  65. }
  66.  
  67. /* return column at which at which buf[i] will be printed */
  68.  
  69. fmtlen(buf,i) char *buf; int i;
  70. {
  71.     return(fmtcol[i]);
  72. }
  73.  
  74. /* print buf[i] ... buf[j-1] on current device so long as
  75.  * characters will not be printed in last column.
  76.  */
  77.  
  78. fmtsubs(buf,i,j) char *buf; int i, j;
  79. {
  80. int k;
  81.     if (fmtcol[i]>=fmtwidth) {
  82.         return;
  83.     }
  84.     outxy(fmtcol[i],outgety());    /* position cursor */
  85.     while (i<j) {
  86.         if (buf[i]==CR) {
  87.             break;
  88.         }
  89.         if (fmtcol[i+1]>fmtwidth) {
  90.             break;
  91.         }
  92.         fmtoutch(buf[i],fmtcol[i]);
  93.         i++;
  94.     }
  95.     outdeol();    /* clear rest of line */
  96. }
  97.  
  98. /* print string which ends with CR or EOS to current device.
  99.  * truncate the string if it is too long.
  100.  */
  101.  
  102. fmtsout(buf,offset) char *buf; int offset;
  103. {
  104. char c;
  105. int col,k;
  106.     col=0;
  107.     while (c=*buf++) {
  108.         if (c==CR) {
  109.             break;
  110.         }
  111.         k=fmtlench(c,col);
  112.         if ((col+k+offset)>fmtwidth) {
  113.             break;
  114.         }
  115.         fmtoutch(c,col);
  116.         col=col+k;
  117.     }
  118. }
  119.  
  120. /* return length of char c at column col */
  121.  
  122. fmtlench(c,col) char c; int col;
  123. {
  124.     if (c==TAB) {
  125.         /* tab every fmttab columns */
  126.         return(fmttab-(col%fmttab));
  127.     }
  128.     else if (c<32) {
  129.         /* control char */
  130.         return(2);
  131.     }
  132.     else {
  133.         return(1);
  134.     }
  135. }
  136.  
  137. /* output one character to current device.
  138.  * convert tabs to blanks.
  139.  */
  140.  
  141. fmtoutch(c,col) char c; int col;
  142. {
  143. int k;
  144.     if (c==TAB) {
  145.         k=fmtlench(TAB,col);
  146.         while ((k--)>0) {
  147.             fmtdevch(' ');
  148.         }
  149.     }
  150.     else if (c<32) {
  151.         fmtdevch('^');
  152.         fmtdevch(c+64);
  153.     }
  154.     else {
  155.         fmtdevch(c);
  156.     }
  157. }
  158.  
  159. /* output character to current device */
  160.  
  161. fmtdevch(c) char c;
  162. {
  163.     if (fmtdev==YES) {
  164.         syslout(c);
  165.     }
  166.     else {
  167.         outchar(c);
  168.     }
  169. }
  170.  
  171. /* output a CR and LF to the current device */
  172.  
  173. fmtcrlf()
  174. {
  175.     if (fmtdev==YES) {
  176.         syslout(CR);
  177.         syslout(LF);
  178.     }
  179.     else {
  180.         /* kludge: this should be in out module */
  181.         /* make sure out module knows position */
  182.         outxy(0,SCRNL1);
  183.         syscout(CR);
  184.         syscout(LF);
  185.     }
  186. }
  187.  
  188. /* set tabs at every n columns */
  189.  
  190. fmtset(n) int n;
  191. {
  192.     fmttab=max(1,n);
  193. }
  194.